import request from '../request'
import type { IResData, ITemplateData } from '../types/requsetType'
import type { TemplateItem } from '@/views/templateList/type'
import {
  defaultCreateWorkProps,
  type ChannelList,
  type IChannelListData,
  type ICreateChannelData,
  type ICreateWorkProps,
  type IGetWorkTemplateListProps,
  type IPublishWorkOrTemplateProps,
  type IWorkDetail,
} from '../types/workType'
import type { ISaveTemplateProps } from '@/store/modules/type/editor'
import type { IWorkTemplateList } from '@/components/workTemplateList/work-template-list.vue'
/**获取作品模板列表 */
export const getWorkTEmplateListAPI = (params?: IGetWorkTemplateListProps) => {
  return request<IResData<ITemplateData<TemplateItem>>>({
    url: '/work/getTemplateList',
    method: 'get',
    params,
  })
}

/**复制作品模板 */
export const copyWorkTemplateAPI = (wordId: string) => {
  return request<IResData<IWorkDetail>>({
    url: '/work/copyWork',
    method: 'get',
    params: {
      id: wordId,
    },
  })
}

/**获取作品详情 */
export const getWorkDtailAPI = (workId: string) => {
  return request.get<IResData<IWorkDetail>>('/work/getWorkDetail', {
    params: {
      id: workId,
    },
  })
}

/**修改作品 */
export const updateWorkAPI = (id: string, data: ISaveTemplateProps) => {
  return request.patch('/work/updateWork', data, {
    params: {
      id,
    },
  })
}
/**创建作品 */
export const createWorkAPI = (
  data: ICreateWorkProps = defaultCreateWorkProps
) => {
  return request.post<IResData<IWorkDetail>>('/work/create', data)
}

/**上传图片接口 */
export const uploadImageAPI = (file: FormData) => {
  return request.post<IResData<string[]>>('/utile/uploadOSS', file, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  })
}
/**发布作品或者模板 */
export const publishWorkOrTemplateAPI = (data: IPublishWorkOrTemplateProps) => {
  return request.post<IResData<string>>('/work/publishWorkOrTemplate', data)
}

/**获取渠道列表 */
export const getChannelListAPI = (id: string) => {
  return request.get<IResData<IChannelListData>>(`/work/channelList/${id}`)
}

/**创建渠道 */
export const createChannelAPI = (data: ChannelList) => {
  return request.post<IResData<ICreateChannelData>>('/work/createChannel', data)
}

/**删除渠道 */
export const deleteChannelAPI = (id: string) => {
  return request.delete(`/work/deleteChannel/${id}`)
}

/**获取个人作品列表 */
export const getPersonalWorkListAPI = (params: IGetWorkTemplateListProps) => {
  return request.get<IResData<ITemplateData<IWorkTemplateList>>>(
    '/work/getMyWorkList',
    {
      params,
    }
  )
}

/**删除作品 */

export const deleteWorkAPI = (id: string) => {
  return request.delete('/work/deleteWork', {
    params: {
      id,
    },
  })
}
